<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>公告设置</span>
    </div>
    <el-form ref="form" label-width="0">
      <el-form-item label="">
        <el-input type="textarea" :rows="5" placeholder="请在此输入公告内容" v-model="text"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="formSub" :loading="load">提交</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
import { homePageNoticeInit, homePageNoticeSub } from '../../../../api/index';
export default {
  data() {
    return {
      id: '',
      text: '',
      load: false,
    };
  },
  created() {
    this.getInit();
  },
  methods: {
    //初始化
    getInit() {
      this.load = true;
      homePageNoticeInit().then(res => {
        this.load = false;
        if (res.code == 0) {
          this.id = res.notice.id;
          this.text = res.notice.content;
        } else {
          this.$message(res.msg);
        }
      })
    },
    //提交
    formSub() {
      this.load = true;
      homePageNoticeSub({
        id: this.id,
        title: '',
        content: this.text
      }).then(res => {
        this.load = false;
        if (res.code == 0) {
          this.$message.success('保存成功');
        } else {
          this.$message(res.msg);
        }
      })
    },
  }
};
</script>

<style scoped>
.box-card {
    margin-bottom: 20px;
}
</style>
